#!usr/bin/python
# -*- coding:utf-8 -*-
import sys
import time
from collections import namedtuple, deque, Counter, OrderedDict, defaultdict


class CollectionsDemo:
    def _test_namedtuple(self):
        """
        cd = CollectionsDemo()
        cd._test_namedtuple()
        """
        websites = [
            ("sohu", "http://www.google.com/", "张朝阳"),
            ("sina", "http://www.sina.com/", "王志东"),
            ("163", "http://www.163.com/", "丁磊"),
        ]
        site = namedtuple('website', ['name', 'url', u'founder'])
        for website in websites:
            website = site._make(website)
            print website

    def _test_deque(self):
        """
        cd = CollectionsDemo()
        cd._test_deque()
        """
        deques = deque(">....................")
        while True:
            deques.rotate(1)
            sys.stdout.flush()
            time.sleep(0.5)
            print deques

    def _test_counter(self):
        """
        cd = CollectionsDemo()
        cd._test_counter()
        """
        s = "I am not a clever boy,but I am well diligent"
        c = Counter(s)
        print c.most_common(5)

    def _test_ordered_dict(self):
        """
        cd = CollectionsDemo()
        cd._test_ordered_dict()
        """
        item = (('A', 1), ('B', 2), ('C', 3))
        s = dict(item)
        os = OrderedDict(item)
        print s, '\n', os
        for k, v in s.items():
            print 'Dict:', k, v, '\t'
        for k, v in os.items():
            print 'OrderedDict:', k, v, '\t'

    def _test_defaultdict(self):
        """
        cd = CollectionsDemo()
        cd._test_defaultdict()
        """
        alpha_num = {'A': 1}
        defaultdict_ = defaultdict(lambda: "N/A")
        print alpha_num['A']
        print defaultdict_['key1']


if __name__ == '__main__':
    cd = CollectionsDemo()
    cd._test_defaultdict()
